<?php

namespace app\model;

use think\Model;

class File extends Model
{
    public function pageData(): array
    {
        $param = request()->param();
        $data = $this->order(['create_time' => 'desc'])->paginate(['list_rows' => 40, 'page' => $param['page'] ?? 1])->toArray();
        return pageData($data);
    }

    public function delData(): array
    {
        $param = request()->param();
        $img = $this->where('id', $param['id'])->find();
        if(empty($img)) return [];
        if(file_exists($img['dir'])) unlink($img['dir']);
        $img->delete();
        return [];
    }
}
